from tcutil cimport uint32_t, uint64_t, bool, TCLIST, TCMAP

cdef extern from "stdlib.h":
    void free(void *ptr)

cdef extern from "tcrdb.h":
    ctypedef struct TCRDB

    ctypedef enum:
        TTESUCCESS
        TTEINVALID
        TTENOHOST
        TTEREFUSED
        TTESEND
        TTERECV
        TTEKEEP
        TTENOREC
        TTEMISC = 9999

    ctypedef enum: # enumeration for scripting extension options
        RDBXOLCKREC = 1 << 0 # record locking
        RDBXOLCKGLB = 1 << 1 # global locking

    TCRDB *tcrdbnew()
    void tcrdbdel(TCRDB *rdb)

    int tcrdbecode(TCRDB *rdb)
    char *tcrdberrmsg(int ecode)

    bool tcrdbopen(TCRDB *rdb, char *host, int port)
    bool tcrdbclose(TCRDB *rdb)

    bool tcrdbput(TCRDB *rdb, void *kbuf, int ksiz, void *vbuf, int vsiz)
    bool tcrdbputkeep(TCRDB *rdb, void *kbuf, int ksiz,  void *vbuf, int vsiz)
    bool tcrdbputcat(TCRDB *rdb, void *kbuf, int ksiz,  void *vbuf, int vsiz)
    bool tcrdbputshl(TCRDB *rdb, void *kbuf, int ksiz,  void *vbuf, int vsiz, int width)
    bool tcrdbputnr(TCRDB *rdb, void *kbuf, int ksiz,  void *vbuf, int vsiz)

    bool tcrdbout(TCRDB *rdb, void *kbuf, int ksiz)

    void *tcrdbget(TCRDB *rdb, void *kbuf, int ksiz, int *sp)
    bool tcrdbget3(TCRDB *rdb, TCMAP *recs)

    TCLIST *tcrdbfwmkeys(TCRDB *rdb, void *pbuf, int psiz, int max)

    int tcrdbvsiz(TCRDB *rdb, void *kbuf, int ksiz)

    bool tcrdbiterinit(TCRDB *rdb)
    void *tcrdbiternext(TCRDB *rdb, int *sp)

    int tcrdbaddint(TCRDB *rdb, void *kbuf, int ksiz, int num)
    double tcrdbadddouble(TCRDB *rdb, void *kbuf, int ksiz, double num)

    void *tcrdbext(TCRDB *rdb, char *name, int opts, void *kbuf, int ksiz, void *vbuf, int vsiz, int *sp)

    bool tcrdbsync(TCRDB *rdb)

    bool tcrdbvanish(TCRDB *rdb)

    bool tcrdbcopy(TCRDB *rdb, char *path)
    bool tcrdbrestore(TCRDB *rdb, char *path, uint64_t ts)

    bool tcrdbsetmst(TCRDB *rdb, char *host, int port)

    uint64_t tcrdbrnum(TCRDB *rdb)
    uint64_t tcrdbsize(TCRDB *rdb)
    char *tcrdbstat(TCRDB *rdb)